package controler;

import java.io.File;
import java.util.HashMap;

import logs.LogLevelEnum;
import logs.LogTypesEnum;
import modele.SimulDynamicDataInterface;
import modele.parameters.SimulParameters;
import controler.interfaces.ControlerAbstract;
import controler.interfaces.ControlerInterface;
import controler.interfaces.MainControlerInterface;
import controler.interfaces.StepReportInterface;
import controler.interfaces.ViewControleurInterface;
import view.interfaces.ViewInterface;

public class ViewControler extends ControlerAbstract implements
		ViewControleurInterface {

	private ViewInterface view;
	private HashMap<String, File> availableSimulations;

	public ViewControler() {
		setName();
	}

	@Override
	public void injectComponents(ViewInterface view) {
		this.view = view;
		this.view.injectModel(((MainControlerInterface) controler).injectModel());
		this.view.setSimulationsNames(availableSimulations);
	}

	@Override
	public void start() {
		view.init(this);
	}

	@Override
	public void setName() {
		setName("View_Controler");
	}

	@Override
	public void askRunSim(String sim) {
		((MainControlerInterface) controler).askRunSim(sim);
	}

	@Override
	public void initwithStaticData(SimulParameters parameters) {

		view.initwithStaticData(parameters);
		// TODO
		logParametersCharged();
	}

	private void logParametersCharged() {
		String log = " (" + this.getName() + ") " + "Parameters charged";
		controler.log(LogLevelEnum.INFO, LogTypesEnum.Params, log);

	}

	@Override
	public void updateAfterStep(StepReportInterface stepReport) {

		view.updateAfterStep(stepReport);

	}

	@Override
	public void initWithDynamicData(SimulDynamicDataInterface dynData) {
		view.initWithDynamicData(dynData);
		view.switchToSimulScreen();
	}

	@Override
	public void quit() {
		controler.quit();
	}

	@Override
	public void triggerAStep() {
		controler.triggerAStep();

	}

	@Override
	public void initSpecificViewDatas(HashMap<String, File> availableSimulations) {
		this.availableSimulations = availableSimulations;

	}
}
